package com.pshcp.service;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.sql.*;

@Slf4j
@Service
public class PatientReportService {

    public void queryReportList(){
        String driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
        String dburl = "jdbc:sqlserver://10.10.1.23;DatabaseName=Anesthesiology_DBbjxh;encrypt=false";
        String userName = "bjyt";
        String userPwd = "bjyt2024";
        try {
            Class.forName(driverName);
            System.out.println("连接成功!!!");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
            System.out.println("驱动加载失败");
        }
        try {
            Connection dbcon = DriverManager.getConnection(dburl,userName,userPwd);
            System.out.println("数据库连接成功！");
            //创建SQl命令对象
            Statement stmt = dbcon.createStatement();
            ResultSet rs = stmt.executeQuery("select * from View_Main_pb_HIS");
            //循环读出每一条数据
            while(rs.next()) {
                System.out.println(rs.getString("name"));
                log.info("读取视图数据信息", rs.getString("name"));
            }
            //关闭对象连接
            stmt.close();
            //关闭数据库连接
            dbcon.close();
        } catch (SQLException e) {
            e.printStackTrace();
            System.out.println("连接失败");
        }
    }
}
